local ServerOHOH = _G.ServerOHOH;
local M = ServerOHOH.class.new(script, ServerOHOH.files.BaseComponent(),script.Parent.Name);

function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);
    self.player=self.parent.player
    self.TopGui=require(script.Parent.TopGui).new(self.parent.main_inst)

    self.DataStore=self.player:GetComponent(_G.ServerOHOH.load.Server_PlayerDataComponent())

    self.parent.player.UserDataEvent:Connect(function(key)
        if key=="base"  then
            self:UpdateTitle()
            self:UpdateLevel()
           
        elseif key=="gamePass"  then
            self:UpdateVip()
        end
    end)

    self:UpdateTitle()
    self:UpdateLevel()
    self:UpdateVip()
end;

local Rebirth_Cfg=ServerOHOH.config.Rebirth
function M.UpdateTitle(self)
    local rid=self.DataStore:GetData("base")["rebirth"]
    local cfg=Rebirth_Cfg[rid]
    if  cfg then
        local tid=cfg.titleId
        self.TopGui:SetTitle(tid)
    else
        self.TopGui:SetTitle(33324075)
    end
end

function M.UpdateLevel(self)
    self.TopGui:SetLevel(self.DataStore:GetData("base").level)
end

function M.UpdateVip(self)
    if self.DataStore:GetData("gamePass")["gamepass_vip"] then
        self.TopGui:SetVip(true)
    end
end

function M.dtor(self)
	M.super.dtor(self);
end;

return M